Skip to main content

Gaussian Blur

A blur filter that uses gaussian function for smoothing.

🖞ïļ Image options and parameters of gaussianBlur method

Gaussian blur is a widely used image processing technique that smooths an image by reducing high-frequency noise and fine details while preserving the overall structure and larger features. It's named after the Gaussian function, which is a mathematical function that represents a bell-shaped curve. Gaussian blur is often applied to images before other processing steps like edge detection to improve their quality and reliability.

The key idea behind Gaussian blur is that it simulates a diffusion process, where each pixel's value is influenced by the values of its neighbors. Because the weights are determined by the Gaussian function, pixels that are closer to the central pixel have a larger impact on the smoothed value, while pixels that are farther away contribute less.

placeholderplaceholder
Ran in 0.00Ξs (Infinity ops/s)

Kinds of images compatible with algorithm​

Image propertyWhat it meansPossible values
bitDepthnumber of bits per channel[8,16]
componentsnumber of componentsany
alphais alpha channel allowedtrue

Parameters and default values​

With Gaussian blur there are two ways of passing options: through sigma and through sigmaX and sigmaY. Main difference is that in first case sigma is the same for X and Y directions.

  • options

Options​

Sigma Variant:​

PropertyRequiredDefault value
sigmayes-
borderTypenoreflect101
outno-
sizeno2 * Math.ceil(2 * sigma) + 1

SigmaXY Variant​

PropertyRequiredDefault value
sigmaXyes-
sigmaYyes-
borderTypenoreflect101
outno-
sizeXno2 * Math.ceil(2 * sigmaX) + 1
sizeYno2 * Math.ceil(2 * sigmaY) + 1

The size of the Gaussian kernel and the standard deviation parameter (which controls the spread of the Gaussian curve) influence the degree of smoothing. A larger kernel or a higher standard deviation will produce more pronounced smoothing, but might also result in a loss of fine details.

Implementation

Here's how Gaussian blur is implemented in ImageJS:

Kernel Definition: The core concept of Gaussian blur involves convolving the image with a Gaussian kernel, also known as a Gaussian filter or mask. This kernel's values are arranged in a way that creates a symmetric, bell-shaped pattern around the center of the kernel to approximate Gaussian function.

Convolution Operation: The Gaussian kernel is applied to the image using a convolution operation. This involves placing the kernel's center over each pixel in the image and performing element-wise multiplication of the kernel's values with the corresponding pixel values in the neighborhood. The results of these multiplications are summed up to compute the new value for the central pixel.

Weighted Averaging: The Gaussian kernel values create a weighting scheme that favors pixels closer to the center of the kernel and decreases the influence of pixels farther away. This is because the Gaussian function is symmetrically distributed around its center, resulting in stronger weights for nearby pixels and weaker weights for distant ones.

Smoothing Effect: As the convolution operation is applied across the entire image, each pixel's value is replaced with a weighted average of its neighboring pixels' values. This process effectively reduces the intensity variations caused by noise and fine details, resulting in a smoothed version of the image.